import { INoticeParam } from '@/interface/notice';
import * as request from './request';

export async function getAllNotice(body: INoticeParam) {
  try {
    const login = sessionStorage.getItem('login')?.toString();
    if (login === '1') {
      const data = await request.post(
        JSON.stringify(body),
        '/api/console/notice/get',
      );
      return data;
    } else {
      return {};
    }
  } catch (e) {
    return e;
  }
}

export async function changeStatuNotice(body: { content: string }) {
  try {
    const data = await request.post(
      JSON.stringify(body),
      '/api/console/notice/changeStatu',
    );
    return data;
  } catch (e) {
    return e;
  }
}

export async function deleteNotice(body: { content: string }) {
  try {
    const data = await request.post(
      JSON.stringify(body),
      '/api/console/notice/remove',
    );
    return data;
  } catch (e) {
    return e;
  }
}

export async function addNotice(body: { content: string; statu: 0 | 1 }) {
  try {
    const data = await request.post(
      JSON.stringify(body),
      '/api/console/notice/add',
    );
    return data;
  } catch (e) {
    return e;
  }
}
